package person.wend.javalearnexample.util;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

public class LocaleExample {

    public static void main(String[] args) {
        dateFormatTest();
        numberAndCurrencyTest();
    }

    public static void dateFormatTest() {
        Date date = new Date();
        Locale localeUs = new Locale("en", "US");
        DateFormat dateFormatUs = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, localeUs);
        System.out.println(dateFormatUs.format(date));

        Locale localeFr = new Locale("fr", "FR");
        DateFormat dateFormatFr = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, localeFr);
        System.out.println(dateFormatFr.format(date));
    }

    // 数字货币格式化
    public static void numberAndCurrencyTest(){
        double number = 1234.56;
        Locale localeGb = new Locale("en", "GB");
        NumberFormat numberFormatGb = NumberFormat.getCurrencyInstance(localeGb);
        System.out.println(numberFormatGb.format(number));

        Locale localeJp = new Locale("ja", "JP");
        NumberFormat numberFormatJp = NumberFormat.getCurrencyInstance(localeJp);
        System.out.println(numberFormatJp.format(number));
    }
}
